﻿using System;
using System.Text;
using System.Data;

using LTJ.Common.Generic;
using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;

namespace LTJ.Data.DataProvider
{
    /// <summary>
    /// 基本类型信息操作
    /// </summary>
    public class BaseTypes
    {
        /// <summary>
        /// 创建基础类型
        /// </summary>
        /// <param name="code">类型代码</param>
        /// <param name="tname">类型名称</param>
        /// <param name="ename">类型英文</param>
        /// <param name="extends">类型扩展</param>
        public static string CreateBaseType(string code, string tname, string ename, string extends)
        {
            return DatabaseProvider.GetInstance().CreateBaseType(code, tname, ename, extends);
        }

        /// <summary>
        /// 根据Code是否存在
        /// </summary>
        /// <param name="code"></param>
        public static BaseTypeInfo GetBaseTypeCode(string code)
        {
            return LoadSingleBaseTypeInfo(DatabaseProvider.GetInstance().GetBaseTypeCode(code));
        }

        /// <summary>
        /// 基础类型分页
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="condition"></param>
        /// <param name="orderstr"></param>
        public static DataTable GetBaseTypesByPage(int pageindex, int pagesize, string condition, string orderstr)
        {
            return DatabaseProvider.GetInstance().GetBaseTypesByPage(pageindex, pagesize, condition, orderstr);
        }
        
        /// <summary>
        /// 基础类型数量
        /// </summary>
        /// <param name="conditions"></param>
        /// <returns></returns>
        public static int GetBaseTypeCount(string conditions)
        {
            return DatabaseProvider.GetInstance().GetBaseTypeCount(conditions);
        }
        /// <summary>
        /// 基础类型数量
        /// </summary>
        /// <param name="bid"></param>
        /// <returns></returns>
        public static int DelBaseType(string bcode)
        {
            return DatabaseProvider.GetInstance().DelBaseType(bcode);
        }

        /// <summary>
        /// 根据基础类型code查询是否有基础数据
        /// </summary>
        public static DataTable GetBaseDataByTypecode(string bcode)
        {
            return DatabaseProvider.GetInstance().GetBaseDataByTypecode(bcode);
        }
        

        /// <summary>
        /// 修改基础类型信息
        /// </summary>
        /// <param name="code"></param>
        /// <param name="tname"></param>
        /// <param name="ename"></param>
        /// <param name="extends"></param>
        public static void UpdateBaseType(string code, string tname, string ename, string extends)
        {
            DatabaseProvider.GetInstance().UpdateBaseType(code, tname, ename, extends);
        }

        #region Helper
        public static BaseTypeInfo LoadSingleBaseTypeInfo(IDataReader reader)
        {
            BaseTypeInfo _info = null;
            if (reader.Read())
            {
                _info = new BaseTypeInfo();
                _info.code = reader["code"].ToString();
                _info.tname = reader["tname"].ToString();
                _info.etname = reader["etname"].ToString();
                _info.expand = reader["expand"].ToString();
            }
            reader.Close();
            return _info;
        }
        #endregion
    }
}
